import java.util.HashMap;
import java.util.Map;

class Solution {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8};
        System.out.println(lenLongestFibSubseq(arr));
    }
    public static int lenLongestFibSubseq(int[] arr) {
        int len = arr.length ;
        int[] dp = new int[len] ;
        Map<Integer,Integer> map = new HashMap<>() ;
        int sum = 0 ;
        for(int i=0 ; i < len ; i ++){
            dp[i] = 1 ;
            for(int j= i-1 ; j >= 1 ; j --){
               dp[i] = Math.max(dp[i] , map.getOrDefault(arr[i]-arr[j] , 0)+1); 
            }
           map.put(arr[i] , dp[i]);
           sum = Math.max(sum , dp[i]);
        }
      return sum ;
    }
}